package com.sxz.sbs.module.order.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sxz.sbs.R;
import com.sxz.sbs.app.GlideApp;
import com.sxz.sbs.applibrary.component.LabelTextView;
import com.sxz.sbs.module.order.mode.OrderhandleBean;
import com.sxz.sbs.view.LabelLinearLayout;

import java.util.List;

/**
 * 订单列表adapter
 * @author hp
 */

public class OrderListAdapter extends BaseQuickAdapter<OrderhandleBean.ListBean,OrderListAdapter.OrderHolder>{
    private OnOrderClickListener onOrderClickListener;
    public OrderListAdapter(@Nullable List<OrderhandleBean.ListBean> data) {
        super(R.layout.item_orderhandle,data);
    }

    public void setOnOrderClickListener(OnOrderClickListener onOrderClickListener) {
        this.onOrderClickListener = onOrderClickListener;
    }

    @Override
    protected void convert(OrderHolder helper, final OrderhandleBean.ListBean item) {
        GlideApp.with(mContext).load(item.getPhotoUrl())
                .placeholder(R.drawable.img_default_stall).into((ImageView) helper.getView(R.id.iv_order));
        helper.setText(R.id.tv_poltname,item.getName());
        helper.setText(R.id.tv_ordertype,item.getStatusStr());
        helper.setText(R.id.tv_order_title,item.getTitle());
        helper.setText(R.id.tv_order_parkingSpace_number,"车位编号："+item.getNumber());
        LabelLinearLayout lllLabel = helper.getView(R.id.lll_label);
        lllLabel.clearChild();
        lllLabel.setOrderListLabels(item.getDiscount());
        helper.setText(R.id.tv_order_price,"¥"+item.getAdvanceMoney());
        helper.setText(R.id.tv_dealprice,"订单总价    ¥"+item.getDealPrice());
        helper.setText(R.id.tv_namephone,item.getPayUserName()+"    "+item.getPayUserPhone());
        if (item.getDealStatus()==1){
            if (item.getHandleStatus() != 0) {
                helper.setGone(R.id.image_item_point,false);
            } else {
                helper.setGone(R.id.image_item_point,true);
            }

        }else {
            helper.setGone(R.id.image_item_point,true);
        }

        if (item.getDealStatus()==1 && item.getIsLeader()==1){
            helper.setGone(R.id.rely_bottom,true);
        }else {
            helper.setGone(R.id.rely_bottom,false);
        }
        //if (item.getDealStatus() == 0) {
            helper.setGone(R.id.rely_bottom,true);
            helper.setGone(R.id.tv_order_list_bottom,false);
            if (item.getStatus() != 4 && item.getStatus() != 5 &&
                    item.getStatus() != 7
                    ) {
                if ( item.getStatus() == 1) {
                    if (item.getAuditStatus() == 1) {
                        helper.setGone(R.id.ltv_modify_order,true);
                    } else {
                        helper.setGone(R.id.ltv_modify_order,false);
                    }
                } else if (item.getStatus() == 6){
                    helper.setGone(R.id.ltv_modify_order,false);
                } else {
                    helper.setGone(R.id.ltv_modify_order,true);
                }
            } else {
                helper.setGone(R.id.ltv_modify_order,false);
            }
            /*if (item.getStatus() != 4 && item.getStatus() != 5 &&
                    item.getStatus() != 6 && item.getStatus() != 7 && item.getAuditStatus() != 1) {
                helper.setGone(R.id.ltv_modify_order,true);
            } else {
                helper.setGone(R.id.ltv_modify_order,false);
            }*/
       // }
        if (item.getIsLeader() == 1 ) {
            //是案场负责人
            if (item.getDealStatus() == 1) {
                //  已分配
                helper.setGone(R.id.rely_bottom,false);
                helper.setGone(R.id.tv_order_list_bottom,true);
                helper.setText(R.id.tv_order_list_bottom,"已分配至 " + item.getTxt_Name() + " 处理");
            } else {
                helper.setGone(R.id.rely_bottom,true);
                helper.setGone(R.id.tv_order_list_bottom,false);
                helper.setGone(R.id.ltv_allot_order,true);
            }
        } else {
            helper.setGone(R.id.rely_bottom,true);
            helper.setGone(R.id.tv_order_list_bottom,false);
            helper.setGone(R.id.ltv_allot_order,false);
        }
        helper.callOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onOrderClickListener != null) {
                    onOrderClickListener.onCallOrder(item.getPayUserPhone());
                }
            }
        });
        helper.allotOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onOrderClickListener != null) {
                    onOrderClickListener.onAllotOrder(item);
                }
            }
        });
        helper.modifyOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onOrderClickListener != null) {
                    onOrderClickListener.onModifyOrder(item);
                }
            }
        });

    }
    public class OrderHolder extends BaseViewHolder {
        LabelTextView allotOrder;
        LabelTextView callOrder;
        LabelTextView modifyOrder;
        public OrderHolder(View view) {
            super(view);
            allotOrder = view.findViewById(R.id.ltv_allot_order);
            callOrder = view.findViewById(R.id.ltv_call_order);
            modifyOrder = view.findViewById(R.id.ltv_modify_order);
        }
    }
    public interface OnOrderClickListener {
        /**
         * 分配订单
         */
        void onAllotOrder(OrderhandleBean.ListBean item);
        /**
         * 订单电话
         */
        void onCallOrder(String phone);
        /**
         * 修改订单
         */
        void onModifyOrder(OrderhandleBean.ListBean item);
    }
}
